//
//  ST_TrophyRankDistanceView.swift
//  btvideo
//
//  Created by mac on 2021/7/9.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit
import SwiftyAttributes

class ST_TrophyRankDistanceView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(gradient_view)
        gradient_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        addSubview(avatar_image_view)
        avatar_image_view.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(15)
            make.width.height.equalTo(48)
            make.left.equalToSuperview().offset(15)
        }
        
        
        addSubview(nickname_label)
        nickname_label.snp.makeConstraints { (make) in
            make.height.equalTo(20)
            make.left.equalToSuperview().offset(73)
            make.top.equalToSuperview().offset(17)
        }
        addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.height.equalTo(17)
            make.left.equalToSuperview().offset(73)
            make.top.equalToSuperview().offset(44)
        }
        
        addSubview(right_label)
        right_label.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-15)
            make.centerY.equalTo(avatar_image_view)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
//    MARK: - properties
    fileprivate lazy var nickname_label:UILabel = {
        let control = UILabel()
        control.textColor = .white
        control.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        control.text = ST_BTUserInfoManager.shared.current_account_info?.userinfo?.nickname
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel()
        control.textColor = .white
        control.font = UIFont.systemFont(ofSize: 12, weight: .regular)
        return control
    }()
    
    fileprivate lazy var right_label:UILabel = {
        let control = UILabel()
        return control
    }()
    
    fileprivate lazy var avatar_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = .scaleAspectFill
        control.cornerRadius = 48/2.0
        control.pin_setImage(from: ST_BTUserInfoManager.shared.current_account_info?.userinfo?.avatar.compress_small_image(width: 48*3).url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        return control
    }()
    
    fileprivate lazy var gradient_view:ST_FWGradientView = {
       let control = ST_FWGradientView()
//        control.model = ST_FWGradientViewModel(colors: [#colorLiteral(red: 0.8039215686, green: 0.631372549, blue: 0.4078431373, alpha: 1),#colorLiteral(red: 0.9529411765, green: 0.8078431373, blue: 0.5882352941, alpha: 1)], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0, y: 1))
        return control
    }()
    
    
    func bind(diff:Float,current:Float,rankType:ST_TrophyRankType){
        
        var title:String
        switch rankType {
        case .财富:
            title = "富豪值："
        default:
            title = "魅力值："
        }
        
        gradient_view.model = rankType.gradient_model
        
        content_label.text = title + String(format: "%.2f", current)
        
        let atr0 = [Attribute.font(.systemFont(ofSize: 12, weight: .regular)),.textColor(.white)]
        
        let rightStr = "还差 ".withAttributes(atr0)
        
        rightStr.append(diff.int.string.withAttributes([Attribute.font(.systemFont(ofSize: 16, weight: .semibold)),.textColor(.white)]))
        
        rightStr.append(" \(title)可上榜".withAttributes(atr0))
        
        right_label.attributedText = rightStr
    }
    
}
